#include "commsmanager.h"

#include <QUrl>
#include <QtNetwork/QHttp>
#include <QDebug>

CommsManager::CommsManager(QObject *parent) :
    QObject(parent)
{
    http =  new QHttp(this);
    connect( http, SIGNAL(requestStarted(int)), this, SLOT(onRequestStarted()));
    connect( http, SIGNAL(requestFinished(int,bool)), this, SLOT(onRequestFinished()));

}


void CommsManager::connectHost()
{
    qDebug() << "CommsManager::connect";
    QUrl url("http://www.google.com/index.html");
    url.setPort( 8080 );
    QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
    http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());

    httpGetId = http->get( QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/") );
    qDebug() << "httpGetId:" << httpGetId;
}

void CommsManager::onRequestStarted()
{
    qDebug() << "onRequestFinished";
}


void CommsManager::onRequestFinished()
{
    qDebug() << "onRequestFinished";
}
